package servlet;

/**
 * @author Lu Ruotong
 * @date 2022/3/13 17:08
 */
import hadoop.HadoopUtil;
import hadoop.Wordcount;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;


@WebServlet("/demo3")
public class Demo3 extends HttpServlet {


    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        // hdfs wc
        String srcPath =  req.getParameter("srcPath");
        String destPath =  req.getParameter("destPath");

        Wordcount wordcount = new Wordcount();
        String  result = "";
        try {
            result  =  wordcount.wc(srcPath,destPath);
        }catch (Exception e){
            e.printStackTrace();
        }


        resp.setContentType("text/html;charset=utf-8");
        PrintWriter pw =  resp.getWriter();
        pw.write(result);


    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }


}

